import { createRouter, createWebHistory } from 'vue-router'
import ConsoleView from '@/views/ConsoleView.vue'
import IndexView from '@/views/IndexView.vue'
import { useRoleGuard } from '@/guard/roleGuard'
import { useLoginGuard } from '@/guard/loginGuard'
import indexChildren from '@/router/indexChildren'
import consoleChildren from '@/router/consoleChildren'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'index',
      component: IndexView,
      children: indexChildren
    },
    {
      path: '/console',
      name: 'console',
      component: ConsoleView,
      meta: { title: '控制台首页' },
      redirect: '/console/dashboard',
      beforeEnter: useLoginGuard,
      children: consoleChildren
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      redirect: {
        name: 'home-404'
      }
    }
  ]
})

router.beforeEach(useRoleGuard)
export default router
